^mlchart.html


001| """mlChart Template (and simple demo).
001| 
001| Don't forget the mlunitsquarechart and mltwocyclechart classes!
001| """

002| ####################################################################################################
003| from os import path
004| from cmath import exp, pi,tau
005| from mlchart import mlchart, mlunitsquarechart, mltwocyclechart
006| ####################################################################################################
007| BasePath = r'C:\CJS\prj\Python\charts'
008| ImgsPath = path.join(BasePath,'img')
009| print()
010| 
011| ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
012| class mlchart_demo (mlchart):
013|     """ML Chart Class."""
014| 
015|     def __init__ (self, data=None, **kwargs):
016|         """New instance."""
017|         super().__init__((8.0, 4.0), **kwargs)
018|         self.data = data
019|         self.title = 'Geometric Sequence: ${5}\\cdot{3}^{x}$'
020|         self.x_title = None #'X-Axis'
021|         self.y_title = None #'Y-Axis'
022|         self.x_limit = (-0.5, +11.5)
023|         self.y_limit = (1, +1000000)
024|         self.x_grids = (1, None)
025|         self.y_grids = (10000, 1000)
026|         self.x_tickf = '%d'
027|         self.y_tickf = '%d'
028|         self.x_tickr = False        # rotate X axis
029|         self.x_dates = False        # use make_x_date_axis
030|         self.title_kw['fontsize'] = 18
031|         self.title_kw['fontweight'] = 'bold'
032|         self.x_title_kw['fontsize'] = 16
033|         self.y_title_kw['fontsize'] = 16
034|         self.fpath = BasePath
035|         self.fname = 'mlchart.png'
036|         self.margins = dict(left=0.07, right=0.98, bottom=0.12, top=0.90)
037| 
038|     def plotter (self):
039|         """Plot something!"""
040|         if self.data is None:
041|             return
042|         # special!
043|         self.ax.set_yscale('log')
044| 
045|         xs1 = self.data[0]
046|         ys1 = self.data[1]
047|         xs2 = self.data[2]
048|         ys2 = self.data[3]
049|         self.ax.bar(xs1,ys1, width=0.6, color='#336699', alpha=0.85, zorder=11)
050|         self.ax.plot(xs2,ys2, c='#ff0000', lw=3.0, alpha=0.66, zorder=12)
051|         #self.ax.legend(loc='lower right', ncol=2, shadow=True)
052| 
053|     def _make_x_axis_spcl (self):
054|         """Rotate X-axis labels 90 degrees. (Same as using x_tickr=True)"""
055|         for tick in self.ax.xaxis.get_major_ticks():
056|             tick.label1.set_rotation('vertical')
057|             tick.label1.set_size(9)
058| 
059| 
060| ##================================================================================================##
061| eye = complex(0, 1)
062| ipi = eye * complex(pi, 0)
063| steps = 600
064| 
065| sv = 5
066| cr = 3
067| 
068| xs1 = list(range(12))
069| ys1 = [sv*pow(cr,x) for x in xs1]
070| print(ys1)
071| 
072| xs2 = [x/100 for x in range(1200)]
073| ys2 = [sv*pow(cr,x) for x in xs2]
074| 
075| data = (xs1, ys1, xs2, ys2)
076| 
077| cht = mlchart_demo(data)
078| cht.make()
079| print('wrote: %s' % path.join(cht.fpath, cht.fname))
080| print()
081| 
082| 
083| print()
084| ####################################################################################################
085| '''eof'''
086|